///////////////////////////////////
// File Name: mBanner.js         //
// By: Manish Kumar Namdeo       //
// BANNER OBJECT
function Banner(objName)
{
	this.obj = objName;
	this.aNodes = [];
	this.currentBanner =Math.floor(Math.random()*3);
	this.intLoopCount = 0;
	this.intBannerFix = -1;
	this.intBannerLong = 0;
};

// ADD NEW BANNER
Banner.prototype.add = function(bannerType, bannerPath, bannerDuration, height, width, hyperlink) {
	this.aNodes[this.aNodes.length] = new Node(this.obj +"_"+ this.aNodes.length, bannerType, bannerPath, bannerDuration, height, width, hyperlink);
};

// Node object
function Node(name, bannerType, bannerPath, bannerDuration, height, width, hyperlink) {
	this.name = name;
	this.bannerType = bannerType;
	this.bannerPath = bannerPath;
	this.bannerDuration = bannerDuration;
	this.height = height
	this.width = width;
	this.hyperlink= hyperlink;
//	alert (name +"|" + bannerType +"|" + bannerPath +"|" + bannerDuration +"|" + height +"|" + width + "|" + hyperlink);
};
// Outputs the banner to the page
Banner.prototype.toString = function() {
	var str = ""
	
	//alert(this.aNodes.length);
	for (var iCtr=0; iCtr < this.aNodes.length; iCtr++) //old: iCtr=0
	    { 
	    //alert(pos);
		str = str + '<span name="'+this.aNodes[iCtr].name+'" '
		str = str + 'id="'+this.aNodes[iCtr].name+'" ';
		str = str + 'class="m_banner_hide" ';
		str = str + 'bgcolor="#FFFCDA" ';	// CHANGE BANNER COLOR HERE
		str = str + 'align="center" ';
		str = str + 'valign="top" >\n';
		if (this.aNodes[iCtr].hyperlink != ""){
			str = str + '<a href="'+this.aNodes[iCtr].hyperlink+'" target="_blank">';
		}
		if ( this.aNodes[iCtr].bannerType == "TEXT" )
		{
			str=str+ '<iframe width="'+this.aNodes[iCtr].width+'" height="'+this.aNodes[iCtr].height+'" src="'+this.aNodes[iCtr].bannerPath+'" marginwidth="0" marginheight="0" scrolling="no" frameborder="0"></iframe> ';
		}	
		if ( this.aNodes[iCtr].bannerType == "FLASH" ){
			str=str+ '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '
			str=str+ 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '
			str=str+ 'width="'+this.aNodes[iCtr].width+'" '
			str=str+ 'height="'+this.aNodes[iCtr].height+'" '
			str=str+ 'id="bnr_'+this.aNodes[iCtr].name+'" align="middle" VIEWASTEXT> '
			str=str+ '<param name="allowScriptAccess" value="always" />'
			str=str+ '<param name="movie" value="'+this.aNodes[iCtr].bannerPath+'" />'
			//str=str+ 'param name="FlashVars" value="'+vars+'" />'
			str=str+ '<param name="wmode" value="transparent" />'
			str=str+ '<param name="menu" value="false" />'
			str=str+ '<param name="quality" value="high" />'
			str=str+ '<embed src="'+this.aNodes[iCtr].bannerPath+'" wmode="transparent" menu="false" quality="high" width="'+this.aNodes[iCtr].width+'" height="'+this.aNodes[iCtr].height+'" name="bnr_'+this.aNodes[iCtr].name+'" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
			str=str+ '</embed></object>'
			
		}else if ( this.aNodes[iCtr].bannerType == "IMAGE" ){
			str = str + '<img src="'+this.aNodes[iCtr].bannerPath+'" ';
			str = str + 'border="0" ';
			str = str + 'height="'+this.aNodes[iCtr].height+'" ';
			str = str + 'width="'+this.aNodes[iCtr].width+'">';
		}

		if (this.aNodes[iCtr].hyperlink != ""){
			str = str + '</a>';
		}

		str += '</span>';
			}
	document.write(str);
str="";
return str;
};

// START THE BANNER ROTATION
Banner.prototype.start = function(){
	if (this.aNodes.length==0)
	{
		return true;
	}
	this.changeBanner();
	var thisBannerObj = this.obj;
	// CURRENT BANNER IS ALREADY INCREMENTED IN changeBanner() FUNCTION
	setTimeout(thisBannerObj+".start()", this.aNodes[this.currentBanner].bannerDuration * 1000);

}

// CHANGE BANNER
Banner.prototype.changeBanner = function(){
	try {
		this.intLoopCount++;
		
		if( this.intLoopCount > this.aNodes.length*3) {
			this.intBannerLong++;
			if( this.intBannerLong%3 != 0) {
				return false;
			}
		}
		
		var thisBanner;
		var prevBanner = -1;
		if (this.currentBanner>this.aNodes.length-1)
		{
			this.currentBanner=0;
		}
		if (this.currentBanner < this.aNodes.length ){
			thisBanner = this.currentBanner;
			if (this.aNodes.length > 1){
				if ( thisBanner > 0 ){
					prevBanner = thisBanner - 1;
				}else{
					prevBanner = this.aNodes.length-1;
				}
			}
			if (this.currentBanner < this.aNodes.length - 1){
				this.currentBanner = this.currentBanner + 1;
			}else{
				this.currentBanner = 0;
			}
		}
		

		if (prevBanner >= 0){
			document.getElementById(this.aNodes[prevBanner].name).className = "m_banner_hide";
		}
		document.getElementById(this.aNodes[thisBanner].name).className = "m_banner_show";
	} catch(e) {}
}


// Advertising.js

function flashWrite(url,w,h,vars,id,bg){

     var flashStr=
    "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
    "<param name='allowScriptAccess' value='always' />"+
    "<param name='movie' value='"+url+"' />"+
    "<param name='FlashVars' value='"+vars+"' />"+
    "<param name='wmode' value='transparent' />"+
    "<param name='menu' value='false' />"+
    "<param name='quality' value='high' />"+
    "<embed src='"+url+"' FlashVars='"+vars+"' wmode='transparent' menu='false' quality='high' width='"+w+"' height='"+h+"' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
    "</object>";
    document.write(flashStr);
}

function DisplayFloatBanner(side)
{
	if( side == 0 ) // ko in gi ca
		return;
		
	if( FloatBanner.length == 0 )
		return;
		
	document.write('<table cellspacing=0 cellpadding=0 border=0 bgcolor="#FFFFFF">');
	
	if (side=='left_150') // ben trai
		for (i=0; i<FloatBanner.length; i++)
			if(FloatBanner[i][2]=='left_150')
				if(FloatBanner[i][0].indexOf(".swf")>0)
				{ 
					document.write('<tr><td>');
	   				flashWrite(PageHost.concat(FloatBanner[i][0]),150,FloatBanner[i][6],FloatBanner[i][1]);
	   				document.write('</td></tr>');
	   			}
	   			else if(FloatBanner[i][0].indexOf(".htm")>0)
	   			{
	   				document.write('<tr><td>');
	   				document.write('<iframe width="');document.write(FloatBanner[i][5]);document.write('" height="');document.write(FloatBanner[i][6]);document.write('" src="');document.write(FloatBanner[i][0]);document.write('" marginwidth="0" marginheight="0" scrolling="no" frameborder="0"></iframe>');
	   				document.write('</td></tr>');
	   			}
				else if(FloatBanner[i][1]=='')
					document.write('<tr><td><a href="/index.php"><img src="', PageHost.concat(FloatBanner[i][0]), '" width=150 border=0></a></td></tr>');
				else 
					document.write('<tr><td><a href="',FloatBanner[i][1],'"><img src="', PageHost.concat(FloatBanner[i][0]), '" width="150" border=0></a></td></tr>');
					
	if (side=='left_110') // ben trai
		for (i=0; i<FloatBanner.length; i++)
			if(FloatBanner[i][2]=='left_110')
				if(FloatBanner[i][0].indexOf(".swf")>0)
				{ 
					document.write('<tr><td>');
	   				flashWrite(PageHost.concat(FloatBanner[i][0]),110,FloatBanner[i][6],FloatBanner[i][1]);
	   				document.write('</td></tr>');
	   			}
	   			else if(FloatBanner[i][0].indexOf(".htm")>0)
	   			{
	   				document.write('<tr><td>');
	   				document.write('<iframe width="');document.write(FloatBanner[i][5]);document.write('" height="');document.write(FloatBanner[i][6]);document.write('" src="');document.write(FloatBanner[i][0]);document.write('" marginwidth="0" marginheight="0" scrolling="no" frameborder="0"></iframe>');
	   				document.write('</td></tr>');
	   			}
				else if(FloatBanner[i][1]=='')
					document.write('<tr><td><a href="/index.php"><img src="', PageHost.concat(FloatBanner[i][0]), '" width=110 border=0></a></td></tr>');
				else 
					document.write('<tr><td><a href="',FloatBanner[i][1],'"><img src="', PageHost.concat(FloatBanner[i][0]), '" width="110" border=0></a></td></tr>');				
		
		
	if (side=='right_150') // ben trai
		for (i=0; i<FloatBanner.length; i++)
			if(FloatBanner[i][2]=='right_150')
				if(FloatBanner[i][0].indexOf(".swf")>0)
				{ 
					document.write('<tr><td>');
	   				flashWrite(PageHost.concat(FloatBanner[i][0]),150,FloatBanner[i][6],FloatBanner[i][1]);
	   				document.write('</td></tr>');
	   			}
	   			else if(FloatBanner[i][0].indexOf(".htm")>0)
	   			{
	   				document.write('<tr><td>');
	   				document.write('<iframe width="');document.write(FloatBanner[i][5]);document.write('" height="');document.write(FloatBanner[i][6]);document.write('" src="');document.write(FloatBanner[i][0]);document.write('" marginwidth="0" marginheight="0" scrolling="no" frameborder="0"></iframe>');
	   				document.write('</td></tr>');
	   			}
				else if(FloatBanner[i][1]=='')
					document.write('<tr><td><a href="/index.php"><img src="', PageHost.concat(FloatBanner[i][0]), '" width="150" border="0"></a></td></tr>');
				else 
					document.write('<tr><td><a href="',FloatBanner[i][1],'"><img src="', PageHost.concat(FloatBanner[i][0]), '" width="150" border=0></a></td></tr>');
					
	if (side=='right_110') // ben trai
		for (i=0; i<FloatBanner.length; i++)
			if(FloatBanner[i][2]=='right_110')
				if(FloatBanner[i][0].indexOf(".swf")>0)
				{ 
					document.write('<tr><td>');
	   				flashWrite(PageHost.concat(FloatBanner[i][0]),110,FloatBanner[i][6],FloatBanner[i][1]);
	   				document.write('</td></tr>');
	   			}
	   			else if(FloatBanner[i][0].indexOf(".htm")>0)
	   			{
	   				document.write('<tr><td>');
	   				document.write('<iframe width="');document.write(FloatBanner[i][5]);document.write('" height="');document.write(FloatBanner[i][6]);document.write('" src="');document.write(FloatBanner[i][0]);document.write('" marginwidth="0" marginheight="0" scrolling="no" frameborder="0"></iframe>');
	   				document.write('</td></tr>');
	   			}
				else if(FloatBanner[i][1]=='')
					document.write('<tr><td><a href="/index.php"><img src="', PageHost.concat(FloatBanner[i][0]), '" width=110 border=0></a></td></tr>');
				else 
					document.write('<tr><td><a href="',FloatBanner[i][1],'"><img src="', PageHost.concat(FloatBanner[i][0]), '" width="110" border=0></a></td></tr>');		
	
	if (side=='right_100') // ben trai
		for (i=0; i<FloatBanner.length; i++)
			if(FloatBanner[i][2]=='right_100')
				if(FloatBanner[i][0].indexOf(".swf")>0)
				{ 
					document.write('<tr><td>');
	   				flashWrite(PageHost.concat(FloatBanner[i][0]),100,FloatBanner[i][6],FloatBanner[i][1]);
	   				document.write('</td></tr>');
	   			}
	   			else if(FloatBanner[i][0].indexOf(".htm")>0)
	   			{
	   				document.write('<tr><td>');
	   				document.write('<iframe width="');document.write(FloatBanner[i][5]);document.write('" height="');document.write(FloatBanner[i][6]);document.write('" src="');document.write(FloatBanner[i][0]);document.write('" marginwidth="0" marginheight="0" scrolling="no" frameborder="0"></iframe>');
	   				document.write('</td></tr>');
	   			}
				else if(FloatBanner[i][1]=='')
					document.write('<tr><td><a href="/index.php"><img src="', PageHost.concat(FloatBanner[i][0]), '" width=100 border=0></a></td></tr>');
				else 
					document.write('<tr><td><a href="',FloatBanner[i][1],'"><img src="', PageHost.concat(FloatBanner[i][0]), '" width="100" border=0></a></td></tr>');					
					
	document.write('</table>');
}
